package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-03-07 00:13
 **/
public class LeetCode504 {

    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }
        int src = num > 0 ? num : -num;
        StringBuilder builder = new StringBuilder();
        while (src > 0) {
            int mod = src % 7;
            builder.append(mod);
            src /= 7;
        }
        builder = builder.reverse();
        if (num < 0) {
            builder.insert(0, '-');
        }
        return builder.toString();
    }

}
